<template>
    <div style="margin: 10px;padding: 10px; width: 100%;background-color: #FFF;border-radius: 10px;" class="container">
      <div class="search">
          <el-input v-model="vagename" placeholder="输入品种名称" style="width: 20% !important;"></el-input>
          <el-button type="primary" icon="el-icon-search" id="search" style="margin-left: 5px;">搜索</el-button>
      </div>

      <div class="box" style="padding: 10px;">
        <el-row>
          <el-col :span="3">
            <el-tabs :tab-position="tabPosition" @tab-click="handleClick">
           <el-tab-pane v-for="(item,index) in formdata" :label="item.vegetables" :vageId="item.vegetablesId" :index="index">
          </el-tab-pane>
        </el-tabs>
          </el-col>

          <el-col :span="17">
            <h3 style="color: #409EFF;">进货记录</h3>
            <el-image v-for="imgs in imglist[index]" :src="imgs" ref="preview" :preview-src-list="imglist[index]" style="width: 30%; height: 30vh; margin: 5px;cursor: pointer;"></el-image>
            <!-- 进货记录 -->
        <avue-crud :option="option"
               :table-loading="loading"
               :data="data"
               ref="crud"
               v-model="form"
               :permission="permissionList"
               @row-del="rowDel"
               @row-update="rowUpdate"
               @row-save="rowSave"
               @search-change="searchChange"
               @search-reset="searchReset"
               @selection-change="selectionChange"
               @current-change="currentChange"
               @size-change="sizeChange"
               :editBtn="true"
               :page="page"
               :upload-after="uploadAfter"
              :upload-delete="uploadDelete"
               @on-load="getrestockload">
        </avue-crud>
           
        </el-col>
        </el-row>

        
        
         
      </div>
    </div>
      
</template>   

<script>
import {getList} from "@/api/system/calssfl"; 
import {getrestock} from "@/api/system/restockRecord"; 
import {setStore, getStore} from '@/util/store';

export default{
    data(){
     return{
            loading:false,
            getvaglist:{
              userId:parseInt(getStore({name: 'userInfo'}).userId),
              roleId:parseInt(getStore({name: 'userInfo'}).roleId)
            },
            data:[],
            form:[],
            formdata:[],
            imglist:[],
            index:0,
            price:0,
            weight:0,
            tabPosition:"left",
            vagename:"",
            buytype:"",
            page: {
              pageSize: 10,
              currentPage: 1,
              total: 1
            },
            option:{
              searchShow: true,
              searchMenuSpan: 6,
              tip: false,
              tree: true,
              border: true,
              selection: true,
              addBtn:false,
              showSummary:true,
              sumColumnList:[
            {
              label:"总计:",
              name:"cartonNum",
              type:"sum"
            },
            {
              label:"总计:",
              name:"cartonPrice",
              type:"sum"
            },
            {
              label:"总计:",
              name:"cartonWeight",
              type:"sum"
            },
            {
              label:"总计:",
              name:"baggedNum",
              type:"sum"
            },
            {
              label:"总计:",
              name:"baggedPrice",
              type:"sum"
            },
            {
              label:"总计:",
              name:"baggedWeight",
              type:"sum"
            }
          ],
              column:[
                // {
                //     label:"批次号",
                //     prop:"batchNum",
                //     slot:true
                // },
                {
                    label:"箱装进货量",
                    prop:"cartonNum"
                },
                {
                    label:"箱装成本价",
                    prop:"cartonPrice"
                },
                {
                    label:"箱装总重量",
                    prop:"cartonWeight"
                },
                {
                    label:"袋装进货量",
                    prop:"baggedNum"
                },
                {
                    label:"袋装成本价",
                    prop:"baggedPrice"
                },
                {
                    label:"袋装总重量",
                    prop:"baggedWeight"
                },
                {
                    label:"进货时间",
                    prop:"addTime"
                },
                {
                    label:"备注",
                    prop:"remark"
                }
              ]
            }
        }
    },
    created(){
      this.onload();
    }, 
    methods:{
       onload(){
         getList(null,null,Object.assign(this.getvaglist, this.query)).then(res=>{
          this.formdata=res.data.data.data;
          this.formdata.forEach(elem=>{
            this.imglist.push(elem.imglist);
          })
          console.log(res);
          console.log(this.imglist);
         })
        },
        searchChange(params, done){
          this.page.currentPage = 1;
          this.getrestockload();
          done();
        },
        searchReset() {
          this.parentId = 0;
          this.getrestockload(this.page);
        },
        currentChange(currentPage){
          this.page.currentPage = currentPage;
        },
        sizeChange(pageSize) {
          this.page.pageSize = pageSize;
        },
        handleClick(event){
            //点击蔬菜分类获取进货记录
            console.log(event.$attrs.vageId);
            console.log(event.$attrs.index);
            console.log(this.imglist[event.$attrs.index])
            this.index = event.$attrs.index;
            this.getrestockload(this.page,this.form,event.$attrs.vageId);
        },
        bzChange(value,weight){
          this.price=value;
          this.weight=weight;
        },
        getrestockload(page, params = {},vageId){
            this.loading = true;
            if(vageId==null){
               params["vageId"]=0;
            }else{
                params["vageId"]=vageId;
            }
            params["roleId"] = this.getvaglist.roleId;
            params["addUserId"] = this.getvaglist.userId;
            // console.log(page.currentPage);
            // console.log(page.pageSize);
            getrestock(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res=>{
                console.log(res);
                this.data=res.data.data.data;
                this.page.total=res.data.data.count;
                this.loading = false;
            })
        }
    }
}

</script>
<style>
  .el-tabs__nav-scroll .el-tabs__nav.is-left{
    height:90vh !important;
    overflow-y:auto;
    overflow-x:hidden;
  }

</style>